package com.qdlc.p2p.quartz.job;

import java.util.List;

import javax.annotation.Resource;

import com.qdlc.p2p.biz.service.BorrowTenderService;
import com.qdlc.p2p.biz.service.UserService;
import com.qdlc.p2p.common.exception.BusinessException;
import com.qdlc.p2p.common.exception.UserException;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.model.BorrowTenderModel;
import com.qdlc.p2p.quartz.AbstractJob;

/**
 * Created by lenovo on 2016/1/7.
 */
public class RepaymentExperience extends AbstractJob {

    @Resource
    private BorrowTenderService borrowTenderService;

    @Resource
    private UserService userService;

    @Override
    protected void process() {
        // 体验金还款
        List<BorrowTenderModel> list = borrowTenderService.repaymentExperience();
        for (BorrowTenderModel tenderModel : list) {
            User user = userService.find(tenderModel.getUserId());
            if (StringUtil.isNotBlank(user.getTppUserCustId())) {
                // 体验金获取利息
                borrowTenderService.repaymentStatus(tenderModel, user);
            } else {
                throw new UserException("您还没有通过实名认证,请先通过实名认证!", BusinessException.TYPE_CLOSE);
            }
        }
    }
}